package org.easystub;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;

public class InvocationReporter {

    private Invocation last;
    private Object reporting;

    void setReportingObject(Object reporting) {
        checkReportingObjectAlreadySet();
        this.reporting = reporting;
    }

    private void checkReportingObjectAlreadySet() {
        if(reporting != null) {
            throw new IllegalStateException("The reporting object has already been set for this reporter");
        }
    }

    public void report(Invocation invocation) {
        assertCorrectObject(invocation.getObjectCalled());
        last = invocation;
    }

    private void assertCorrectObject(Object objectCalled) {
        if(reporting != objectCalled) {
            throw new IllegalArgumentException("invocation is for a different object to the object this reporter is reporting for");
        }
    }

    public Invocation lastInvocation() {
        return last;
    }

}
